﻿using JTT.Dev.Toolkit.Sys;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JTT.GUIDCreator.UI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (SystemHelper.CheckLowestWin81())
            {
                MessageBox.Show("不支持Win8.1以下的操作系统！");
                Application.Exit();
            }
        }

        private void Create_Button_Click(object sender, EventArgs e)
        {
            Result_ListBox.Items.Clear();
            Int32 GUIDNumber = Convert.ToInt32(GUIDNumber_NumbericUpDown.Value);
            for (Int32 i = 1; i <= GUIDNumber; i++)
            {
                Result_ListBox.Items.Add(CreateSingleGUID(Upper_CheckBox.Checked, Brace_CheckBox.Checked, Dash_CheckBox.Checked));
            }
        }

        /// <summary>
        /// 产生单个GUID
        /// </summary>
        /// <param name="_Upper">是否大写</param>
        /// <param name="_Brace">是否大括号</param>
        /// <param name="_Dash">是否有破折号</param>
        /// <returns></returns>
        private String CreateSingleGUID(Boolean _Upper, Boolean _Brace, Boolean _Dash)
        {
            Guid OriginalGuid = Guid.NewGuid();
            String OriginalGuidString = OriginalGuid.ToString("D");
            if (!_Dash)
            {
                OriginalGuidString = OriginalGuidString.Replace("-", "");
            }
            if (_Upper)
            {
                OriginalGuidString = OriginalGuidString.ToUpper();
            }
            if (_Brace)
            {
                OriginalGuidString = "{" + OriginalGuidString + "}";
            }
            return OriginalGuidString;
        }

        private void Result_ListBox_DoubleClick(object sender, EventArgs e)
        {
            if (Result_ListBox.SelectedIndex >= 0)
            {
                Clipboard.SetText(Convert.ToString(Result_ListBox.SelectedItem));
            }
        }

        private void CheckUpdate_Button_Click(object sender, EventArgs e)
        {
            //调用系统默认的浏览器   
            System.Diagnostics.Process.Start("explorer.exe", "http://www.jututa.com");
        }
    }
}
